package functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.utils;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.units.AnnotatedGene;
import functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.units.Gene;

/**
 * This class contains methods for easy reading and writing of files.
 * @author Jamie MacPherson
 */
public class FileUtils {


    /**
     * This method will return a BufferedReader when passed a File to read
     * An exception is thown if the file doesn't exist.
     * @param file - the file to be written to.
     * @return the BufferedReader.
     */
    public static BufferedReader getBufferedReader(File file) {
        try {
            return new BufferedReader(new FileReader(file));
        } catch (FileNotFoundException ex) {
            System.out.println(file.getPath() + " does not exist, please supply a valid file path");
            System.out.println("exiting program");
            ex.printStackTrace();
            System.exit(0);
        }
        return null;
    }


    /**
     * This method will return a BufferedWriter when passed a File to write to.
     * @param file the file to be written to.
     * @return the BufferedWriter.
     */
    public static BufferedWriter getBufferedWriter(File file) {
        try {
            return new BufferedWriter(new FileWriter(file));
        } catch (IOException ex) {
            System.out.println(file.getPath() + " does not exist, please supply a valid file path");
            System.out.println("exiting program");
            ex.printStackTrace();
            System.exit(0);
        }
        return null;


    }
}
